 def normalize_first_form	
          root_table_array = get_root_tables("first_normalize_config.csv")
          new_connection = create_new_connection
          for root_table in root_table_array
                primary_key = get_primary_key(root_table)
                handle_primary_key(primary_key,root_table,new_connection)
                create_structure_csv_file(root_table,new_connection)
                FasterCSV.foreach("first_normalize_config.csv") do |row|
                      if row.first == "child tables" 
                          for i in 3..row.length-1
                              if row[1] == root_table
                                  if row[i] != nil
                                      row[i] = row[i].gsub(' ','_')
                                      column_struc = get_the_col_spec_for_single_col(row[i],root_table,new_connection)
                                      if i == 3
                                            if [primary_key,primary_key.upcase,primary_key.downcase,primary_key.capitalize].include? row[i]  
                                                  new_connection.query("CREATE TABLE #{row[2]}(#{row[i]} #{column_struc})")
                                            else
                                                  new_connection.query("CREATE TABLE #{row[2]}(#{row[i]} #{column_struc})")		
                                            end	
                                      else
                                          if [primary_key,primary_key.upcase,primary_key.downcase,primary_key.capitalize].include? row[i]
                                                new_connection.query("ALTER TABLE #{row[2]} ADD #{row[i]} #{column_struc}")
                                          else
                                                new_connection.query("ALTER TABLE #{row[2]} ADD #{row[i]} #{column_struc}")
                                          end	
                                      end	
                                  end	
                              end	
                          end
                      end
                end	
          end
 end	

 
 def get_primary_key(tablename)
        FasterCSV.foreach("first_normalize_config.csv") do |row|
              if row.first == "primary key"
                    for field_counter in 0..row.length
                          if row[field_counter] == tablename
                                return row[field_counter + 1]
                          end
                    end	
              end	
        end	
 end


 def create_first_normalization_config_file
        first_norm_file = File.new("first_normalize_config.csv","w")
        first_norm_file.write("root table,")
        first_norm_file.write("\n")	
        first_norm_file.write("primary key,")
        first_norm_file.write("\n")
        first_norm_file.write("child tables,")
        first_norm_file.write("\n")
        first_norm_file.write("child tables,")
        first_norm_file.write("\n")
        first_norm_file.write("comments,")
        first_norm_file.write("for adding more child tables copy above two child table records and provide desired values.")
        first_norm_file.close
end	
